﻿<%@ Page Title="" Language="C#" MasterPageFile="~/SIPO.master" AutoEventWireup="true" CodeFile="recPaymentlist.aspx.cs" Inherits="SIPO.Web.Lists.Transaction.recPaymentlist" %>

<asp:Content ID="Content1" ContentPlaceHolderID="body" Runat="Server">
    <link type="text/css" rel="stylesheet" href="<%= ResolveUrl("~/styles/ui.jqgrid.css") %>" />
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/i18n/grid.locale-id.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/jquery.jqGrid.min.js") %>"></script>
    <script src="<%= ResolveUrl("~/scripts/helper.js") %>" type="text/javascript"></script>
    
    <div>
    <button id="btnAdd" type="button" onclick="OpenForm('add');">
        Tambah</button>
    <button id="btnEdit" type="button" onclick="OpenForm('edit');">
        Ubah</button>
    <button id="btnDelete" type="button" onclick="OpenForm('delete');">
        Hapus</button>
    <button id="btnLoadRekKoran" type="button" onclick="OpenForm('load');">
        Load Rek. Koran</button>
   <%-- <button id="btnAutoRekonsiliasi" type="button" onclick="OpenForm('auto');" >
        Automatic Rekonsiliasi</button>--%>
        <button id="btnUpdate" type="button" onclick="OpenForm('update');" >
        Ubah Pembayaran</button>
    </div>
    
    <br />
    <br />
    <table id="table" class="scroll" cellpadding="0" cellspacing="0">
    </table>
    <div id="pager" class="scroll">
    </div>
    <div id="dialog" title="Default dialog">
    </div>
    
    <script type="text/javascript">
        $("#btnAdd").button({ icons: { primary: "ui-icon-plus"} });
        $("#btnEdit").button({ icons: { primary: "ui-icon-pencil"} });
        $("#btnDelete").button({ icons: { primary: "ui-icon-trash"} });
        $("#btnLoadRekKoran").button({ icons: { primary: "ui-icon-pencil"} });
        //$("#btnAutoRekonsiliasi").button({ icons: { primary: "ui-icon-pencil"} });
        $("#btnUpdate").button({ icons: { primary: "ui-icon-pencil"} });
    </script>
    
    <script type="text/javascript">
        var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Transaction/recPaymenthandler.ashx") %>';
        $('#table').jqGrid({
            url: handlerUrl + '?method=getdata',
            datatype: 'json',
            colNames: ['ID', 'Sector', 'Sub Sector', 'Sub Sub Sector', 'Perusahaan', 'No. Pembayaran', 'Tgl. Pembayaran', 'Jumlah Pembayaran (Rp)', 'No. Surat Setoran', 'Jumlah Surat Setoran (Rp)', 'Selisih (Rp)'],
            colModel: [
                    { name: 'PaymentID', hidden: true, index: 'PaymentID', width: 60 },
                    { name: 'SectorName', index: 'SectorName', width: 100, hidden: true, searchoptions: { searchhidden: true} },
                    { name: 'SubSectorName', index: 'SubSectorName', width: 100, hidden: true, searchoptions: { searchhidden: true} },
                    { name: 'SubSubSectorName', index: 'SubSubSectorName', width: 400 },
                    { name: 'DebtorName', index: 'DebtorName', width: 300 },
                    { name: 'PaymentNo', index: 'PaymentNo', align: 'left', width: 300 },
                    { name: 'PaymentDate', index: 'PaymentDate', align: 'center', width: 350, formatter: 'date', formatoptions: { newformat: 'd M Y'} },
                    { name: 'PaymentValue', index: 'PaymentValue', formatter: 'number', align: 'right', width: 300 },
                    { name: 'InvoiceNo', index: 'InvoiceNo', align: 'left', width: 350 },
                    { name: 'InvoiceValue', index: 'InvoiceValue', formatter: 'number', align: 'right', width: 320 },
                    { name: 'selisih', index: 'selisih', formatter: 'number', align: 'right', width: 300 }

           	],
            rowNum: 10,
            id: 'recPayment.PaymentNo',
            multiselect: true,
            rowList: [5, 10, 15, 20],
            pager: '#pager',
            sortname: 'recPayment.PaymentNo',
            sortorder: "desc",
            viewrecords: true,
            jsonReader: { repeatitems: false },
            width: 1250,
            height: '100%',
            caption: 'Pembayaran',
            ajaxGridOptions: { cache: false },
            ondblClickRow: function () {
                OpenForm('edit');
            }
        });

        $("#table").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, searchtext: 'Search', refreshtext: 'Refresh' },
        {}, {}, {}, { closeOnEscape: true, multipleSearch: true, closeAfterSearch: true });

        function OpenForm(ctl) {

            var formUrl = '<%= ResolveUrl("~/forms/transaction/recPaymentform.aspx") %>';
            var formUrl1 = '<%= ResolveUrl("~/forms/transaction/recPaymentLoadRekKoranform.aspx") %>';
            var formUrl2 = '<%= ResolveUrl("~/forms/transaction/recPaymentAutoRekonsiliasiform.aspx") %>';
            var formUrl3 = '<%= ResolveUrl("~/forms/transaction/recPaymentUpdateform.aspx") %>';
            var grid = $('#table');
            var selIds = grid.jqGrid('getGridParam', 'selarrrow'),
                selText = [];
            $.each(selIds, function () {
                selText.push(grid.jqGrid('getCell', this, 'PaymentID'));
            });



            if (ctl == 'edit') {
                if (selIds.length == 0) {
                    alert('Pilih data yang mau di ubah !');
                }
                else if (selIds.length > 1) {
                    alert('Pilih satu record untuk ubah data.');
                }
                else {
                    $('#dialog').load(formUrl + '?id=' + selText + '&menuId=' + '<%= base.MenuID %>').dialog({ autoOpen: false, modal: true, width: 600, title: 'Ubah Pembayaran' });
                    $("#dialog").dialog('open');
                }
            }
            else if (ctl == 'add') {
                $('#dialog').load(formUrl + '?menuId=' + '<%= base.MenuID %>').dialog({ autoOpen: false, modal: true, width: 600, title: 'Tambah Pembayaran' });
                $("#dialog").dialog('open');
            }
            else if (ctl == 'load') {
                $('#dialog').load(formUrl1).dialog({ autoOpen: false, modal: true, width: 500, title: 'Load Rek Koran' });
                $("#dialog").dialog('open');
            }
            else if (ctl == 'auto') {
                $('#dialog').load(formUrl2).dialog({ autoOpen: false, modal: true, width: 500, title: 'Automatic Rekonsiliasi' });
                $("#dialog").dialog('open');
            }
            else if (ctl == 'update') {
                $('#dialog').load(formUrl3).dialog({ autoOpen: false, modal: true, width: 850, title: 'Update Pembayaran' });
                $("#dialog").dialog('open');
            }
            else {

                if (selIds.length == 0)
                    alert('Pilih data yang mau di hapus !');
                else {
                    var result = window.confirm('Benar data akan di hapus ?');
                    if (result) {

                        var objrecPayment = new Object();
                        objrecPayment.PaymentID = encodeURIComponent(selText);
                        jsonData = JSON.stringify(objrecPayment);
                        CallAjax('<%= ResolveUrl("~/ajaxhandler/transaction/recPaymenthandler.ashx") %>', "?method=delete", jsonData);
                        setTimeout("$('#table').trigger('reloadGrid');", 3000);
                    }
                }

            }
        }
        
    </script>
    <br />
    <br />
    <br />
    <br />
</asp:Content>

